﻿import Taro, { Component } from '@tarojs/taro'
import { Swiper, SwiperItem, Image, View, Text } from '@tarojs/components'
import '../../assets/common.scss'
import CommonJs from '../../utils/common'
import './pointsdetails.scss'
import cat04 from '../../assets/kedouimg01/sckf.png'
import xl from '../../assets/kedouimg01/xl.png'
import goto from '../mall/images/goto01.png'

export default class Index extends Component {
  constructor(props) {
    super(props);
    this.state = {
	  result:[],
	  results:[],
      pageNumber:0,//页码数
      scrollPd:false,//是否可滑动
      hasNextPage:false,//是否有下一页  
      norecords:'',
      money:0,
      balanceCyzs:0,
	  indexCIFormula:0,
	  islisyr:0,
	  createDateEnd:'',
	  appmark:CommonJs.getmark(),
    }
  }
  config = {
    navigationBarTitleText: '加载中'
  }
  componentWillMount () {
	if(this.state.appmark=='xjzb'){
		Taro.setNavigationBarTitle({title:'信用资产'})
	}
	else{
		Taro.setNavigationBarTitle({title:'任务贡献'})
	}
	var money =this.$router.preload.money;
	var indexCIFormula =this.$router.preload.indexCIFormula;
	var balanceCyzs =this.$router.preload.balanceCyzs;
	this.setState({
		money:money,
		indexCIFormula:indexCIFormula,
		balanceCyzs:balanceCyzs,
	  })
    this.getdate(0)
    this.getcydate(0)
  }
  componentDidShow () {
  	
  }

  getdate(pageNumber){
	var url='/crm/papi/v1.9/entrepreneur-exponent?usageStatus.equals=YES'
	var _this=this
	var dates={
	  size:10,
	  page:pageNumber
  }
CommonJs.ajaxRequest(url,dates,'GET',function(res){
	if (res) {

		  if(res.data.totalPages>pageNumber){
			var hasNextPage = true;
		}
		  else{
			  var hasNextPage = false;
		  }
	  var result = res.data.list
	  var results = _this.state.result
	  for(var i = 0; i < result.length; i++){
		results.push(result[i]);
	  }
	  if (hasNextPage) {
		_this.setState({
		  result: results,
		  znwns: '暂无数据',
		  pageNumber: res.data.page,
		  hasNextPage: hasNextPage,
		  scrollPd: true
		})
	  }
	  else {
		_this.setState({
		  result: results,
		  znwns: '暂无数据',
		  pageNumber: res.data.page,
		  hasNextPage: hasNextPage,
		  scrollPd: false
		})
	  }
	} else {
	  _this.setState({
		znwns: '暂无数据'
	  })
	}
  },"wfw")
}

getcydate(pageNumber){
    var _this=this
 	if(_this.state.createDateEnd != ''){
 	 	var url = '/crm/papi/v1.9/currency?assetType=CYZS'+ '&createDateEnd=' + _this.state.createDateEnd
 	 }else{
 	 	var url = '/crm/papi/v1.9/currency?assetType=CYZS'
 	 }
    var dates={}

    CommonJs.ajaxRequest(url,dates,'GET',function(res){
  	if (res.data.length>0) {
		  var results = _this.state.results  
		  var result = res.data[0].assetTypeDetailsList
		  if(pageNumber==0){
			results=[]
		  }
  		for(var i = 0; i < result.length; i++){
  		  results.push(result[i]);
  		}
  		  _this.setState({
			  results: results,
			  pageNumber:1
  		  })     
  	  } 
  	},"wfw")
  }  
loadMore(){

var _this = this
var pd = _this.state.scrollPd
if(pd) {
  //防止多次触发滑动到底部事件
  _this.setState({
	scrollPd: false//禁止下拉
  })
  var pageNumber = _this.state.pageNumber + 1
  _this.getdate(pageNumber)
}else{
  var hasNextPage =  _this.state.hasNextPage
  if(hasNextPage){
	Taro.showToast({
	  title:'正在加载数据...',
	  icon: 'none',
	  duration: 2000
	})
  }else{
	Taro.showToast({
	  title:'没有更多数据啦！',
	  icon: 'none',
	  duration: 2000
	})
  }
}
}


onDateChange(e){
	var _this = this;
  var createDateEnd = _this.state.createDateEnd
  var evalue = e.detail.value
	  createDateEnd =evalue
	  _this.setState({
		  results:[],
		  createDateEnd:createDateEnd,
		  islisyr:1
		  
		})
	setTimeout(function(){
		_this.getcydate(0)
	},600)
}
  
  render () {
	const result = this.state.result
	const results = this.state.results
	const appmark = this.state.appmark
    return (
      <View className='page'>
	   <ScrollView className='qun-mingxibo' scrollY='true' onScrollToLower={this.loadMore.bind(this,'')}>
       	<View className='gxq-tj'>
				<View className='gxq-top' style={appmark=='xjzb'?'':'display:none'}>信用资产={this.state.indexCIFormula}</View>
				<View className='gxq-top' style={appmark=='xjzb'?'display:none':''}>任务贡献={this.state.indexCIFormula}</View>
				<View className='wdt-lis'>
							<Picker mode='date' onChange={this.onDateChange.bind(this)} fields='month'>
                			  <View className='picker'>{this.state.islisyr == 1 ?this.state.createDateEnd : '本月'}<Image className='xl' mode='widthFix' src={xl}></Image></View>
              				</Picker>
						</View>
				<View className='gxq-top-list'>
					<View className='gxq-top-li'>
    				<View className='gxq-text' style={appmark=='xjzb'?'padding:35px 0 5px 0':'display:none;padding:35px 0 5px 0'}>信用资产</View>
    				<View className='gxq-text' style={appmark=='xjzb'?'display:none;padding:35px 0 5px 0':'padding:35px 0 5px 0'}>任务贡献</View>
    				<View className='gxq-num'>{this.state.money/100}</View>
					</View>

					<View className='gxq-top-li'>
    				<View className='gxq-text' style='padding:35px 0 5px 0'>创业指数</View>
    				<View className='gxq-num'>{this.state.balanceCyzs/100}</View>
					</View>
					</View>
    				<View className='gxq-mytj'>
    					<View className='gxq-mytj-li'>
    							<Text className='gxq-mytj-text'>企业认证</Text>
    					</View>
    					<View className='gxq-mytj-li'>
    							<Text className='gxq-mytj-text'>个人认证</Text>
    					</View>
    				</View>
    			</View>
    		<View className='tuiguan-list' style='border-top:none;'>
       				<View className='mobile'>
       					<Text className='tuiguan-tit'>指数提升</Text>
			        	<View className='zjlist myflex'>
						<View className='nodate' style={!result||result.length==0?'':'display:none'}>暂无数据</View>
						{result.map((item, index) => (
				    			<View className='zjli'>
				    			  <View className='zjimg'><Image className="img" mode="scaleToFill" src={cat04}></Image></View>
									 <View className='zjname'>{item.name}+{item.typeId==1?item.exponent+'%':item.exponent/100}</View>
				    			</View>
								))}
			        	</View>
			        	
			        </View>
					<View className='cy-list'>
       					<Text className='tuiguan-tit'>创业数据明细</Text>

						   <View className='qun-mingxibo'>
					   <View className='nodate' style={!results||results.length==0?'':'display:none;'}>暂无数据</View>
						   {results.map((item,index)=>(
	       				<View className='qun-mingxilist'>
			              <View className='qun-mngxicont'>
			                <View className='qun-mngxileft'>
			                  <Text className='qun-minxizngs qun-reanao'>{item.note}</Text>
			                  <Text className='qun-minxizngs qun-minxitit'>{CommonJs.FormatDate(item.createAt,3)}</Text>
			                </View>
			                <View className='qun-mngxiright'>
			                  <Text style="margin-top:0" className={this.state.navindex==1?'qun-minxizngs qun-minxijine':'qun-minxizngs qun-minxijine qun-colors'}>{item.changeAmount/100}</Text>
			                </View>
			              </View>
			          </View>
					  ))}
			        </View>
			        	
			        </View>
       		</View>
		</ScrollView>
      </View>
    )
  }
}

 